package com.quanyan.ic.vendingMachine.http.controller;

import com.quanyan.ic.common.http.APIResponse;
import com.quanyan.ic.vendingMachine.http.service.VmOrderService;
import com.quanyan.ic.vendingMachine.model.OrderCallbackResult;
import com.quanyan.ic.vendingMachine.model.ShoppingCart;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Created by zhuo.shi on 2017/7/26.
 */
@RestController
@RequestMapping("/larkic/vendingMachine/order")
public class VmOrderController {

    @Autowired
    private VmOrderService vmOrderService;

    @RequestMapping("/scanQrCodePay")
    public APIResponse scanQrCodePay(@RequestBody ShoppingCart shoppingCart, HttpServletRequest request) {
        return APIResponse.returnSuccess(vmOrderService.scanQrCodePay(shoppingCart, request));
    }

    @RequestMapping("/scanQrCodePay/callback")
    public APIResponse scanQrCodePayCallback(@RequestBody OrderCallbackResult result) {
        return APIResponse.returnSuccess(vmOrderService.processOrderPayCallback(result));
    }

    @RequestMapping("/findOrder")
    public APIResponse findOrder(@RequestBody Map<String, String> map) {
        String orderNo = MapUtils.getString(map, "orderNo");
        return APIResponse.returnSuccess(vmOrderService.findOrder(orderNo));
    }
}